package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.data.ResultEnum;
import com.dongdongshop.pojo.seller.TbSeller;
import com.dongdongshop.service.SellerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("seller")
public class SellerController {
    @Reference
    private SellerService sellerService;

    private final Logger logger= LoggerFactory.getLogger(SellerController.class);
    @RequestMapping("toList")
    public String toList(){
        return "admin/seller_1";
    }

    @RequestMapping("listSeller")
    @ResponseBody
    public Result listSeller(String name,String nickName){
        try {
            List<TbSeller> list=sellerService.listSeller(name,nickName);
            return Result.response(ResultEnum.OK).setData(list);
        }catch (Exception e){
            logger.info("错误");
            return Result.response(ResultEnum.FAIL);
        }
    }
    //查看详情
    @RequestMapping("selectSellerId/{sellerId}")
    @ResponseBody
    public Result selectSellerId(@PathVariable("sellerId")String sellerId){
        System.out.println(sellerId+"++++++++++++++++++++++++++");
        try {
            TbSeller tbSeller=sellerService.selectById(sellerId);
            System.out.println("---------"+tbSeller);
            return Result.response(ResultEnum.OK).setData(tbSeller);
        }catch (Exception e){
            logger.info("错误");
            return Result.response(ResultEnum.FAIL);
        }
    }

    //审核
    @RequestMapping("status")
    @ResponseBody
    public Result status(String sellerId,String status){
        try {
           int i= sellerService.update(sellerId,status);
            return Result.response(ResultEnum.OK);
        }catch (Exception e){
            logger.info("错误");
            return Result.response(ResultEnum.FAIL);
        }
    }
}
